package com.lovely3x.jobservice.executors.extensions.version.factory;

import com.lovely3x.jobservice.JobService;
import com.lovely3x.jobservice.executors.TaskExecutor;
import com.lovely3x.jobservice.executors.extensions.version.executor.VersionCheckExecutor;
import com.lovely3x.jobservice.factory.ExecutorFactory;
import com.lovely3x.jobservice.serializer.TaskSerializer;
import com.lovely3x.jobservice.task.Task;

import java.util.ArrayList;

//import com.lovely3x.jobservice.executors.extensions.version.serializer.VersionCheckSerializer;

/**
 * 版本
 * Created by lovely3x on 16-2-18.
 */
public class VersionCheckFactory implements ExecutorFactory {

    /**
     * 执行器类型
     */
    public static final String EXECUTOR_TYPE = "version_check";
    private final ArrayList<VersionCheckExecutor> executors = new ArrayList<>();
    // private VersionCheckSerializer mCheckSerializer;
    private JobService mJobService;

    @Override
    public TaskExecutor createExecutor(Task task) {
        VersionCheckExecutor vce;
        if (task != null && EXECUTOR_TYPE.equals(task.getTaskType())) {
            vce = new VersionCheckExecutor();
            executors.add(vce);
            vce.onCreate(mJobService);
            return vce;
        }
        return null;
    }

    @Override
    public TaskSerializer getTaskSerializer() {
        return null;
    }

    @Override
    public boolean isBusy() {
        return false;
    }

    @Override
    public boolean handleable(Task task) {
        return task != null && EXECUTOR_TYPE.equals(task.getTaskType());
    }

    @Override
    public void onCreate(JobService service) {
        this.mJobService = service;
        //   this.mCheckSerializer = new VersionCheckSerializer();
        //   this.mCheckSerializer.onCreate(mJobService);
    }

    @Override
    public void onDestroy(JobService service) {
        for (VersionCheckExecutor versionCheckExecutor : executors) {
            versionCheckExecutor.onDestroy();
        }
        //   mCheckSerializer.onDestroy();
        mJobService = null;
    }

    @Override
    public void performOnCreate(TaskExecutor executor) {

    }

    @Override
    public void performOnDestroy(TaskExecutor executor) {

    }
}
